Skip to content

fix: prevent duplicate alias in --empty mode for inline ref/source#1397

Merged
sd-db merged 4 commits intomainfrom
sd-db/triage/dbt-empty-inline-ref-alias
Apr 16, 2026
Merged

fix: prevent duplicate alias in --empty mode for inline ref/source#1397
sd-db merged 4 commits intomainfrom
sd-db/triage/dbt-empty-inline-ref-alias

Conversation

@sd-db
Copy link
Copy Markdown
Collaborator

@sd-db sd-db commented Apr 14, 2026

Summary

  • Sets require_alias: bool = False on DatabricksRelation, preventing render_limited() from injecting a _dbt_limit_subq_* alias that conflicts with user-provided AS aliases when running dbt run --empty
  • Adds conformance tests for --empty mode (BaseTestEmpty and BaseTestEmptyInlineSourceRef)
  • Adds a unit test verifying render_limited() output has no trailing subquery alias

Context

When dbt run --empty is used, dbt wraps ref() and source() in a zero-row subquery. BaseRelation defaults to require_alias=True, which appends an auto-generated alias (_dbt_limit_subq_{table}). If the user also has an AS alias in their SQL (e.g. {{ ref('orders') }} AS orders), the two aliases conflict and produce invalid SQL.

Databricks SQL does not require subquery aliases, so require_alias should be False.

Resolves dbt-labs/dbt-adapters#660 for Databricks.

Test plan

  • Unit test: test_render_limited_with_empty_no_alias — asserts render_limited() produces no trailing alias with limit=0
  • Functional test: TestDatabricksEmptyInlineSourceRef — end-to-end against live cluster, dbt run --empty with inline source alias
  • Functional test: TestDatabricksEmpty — general --empty conformance
  • All 721 existing unit tests pass (0 regressions)

DatabricksRelation inherited require_alias=True from BaseRelation, causing
render_limited() to inject a _dbt_limit_subq_* alias that conflicts with
user-provided AS aliases when running dbt run --empty.

Databricks SQL does not require subquery aliases, so require_alias should be False.

Resolves dbt-labs/dbt-adapters#660 for Databricks.
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 14, 2026

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  dbt/adapters/databricks
  relation.py
Project Total  

This report was generated by python-coverage-comment-action

@sd-db sd-db merged commit 3d3a87d into main Apr 16, 2026
10 checks passed
@sd-db sd-db deleted the sd-db/triage/dbt-empty-inline-ref-alias branch April 16, 2026 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Model reference and AS with --empty run fails

2 participants